//导入 createSlice 函数
import { PayloadAction, createSlice } from '@reduxjs/toolkit';

interface CounterState {
  value: number
}

//创建初始状态
const initialState: CounterState = {
  value: 0
};

//创建 countSlice
export const countSlice = createSlice({
  name: 'count',
  initialState,
  reducers: {
    //增加
    increment: (state, action: PayloadAction<number>) => {
      state.value += action.payload;
    },
    //减少
    decrement: (state, action) => {
      state.value -= action.payload;
    }
  }
})

//导出 actions
export const { increment, decrement } = countSlice.actions;

//导出 reducer
export default countSlice.reducer;
